<?php

// 网站信息表

namespace app\console\model;

use think\Model;
use think\Request;

class Information extends Model
{

    // 新闻信息 信息类型关联
    public function InformationType()
    {
        return $this->belongsTo('InformationType','parenTid','id')->field('id,title');
    }

    // 模型事件
    protected static function init()
    {
        // 新增之前
        self::event('before_insert',function ($data){
            $data->create_time = date('Y-m-d',time());
        });


        // 写入前
        self::event('before_write', function ($data) {
            $data->picUrl = uploadImg('picUrl', 'shop');                                                //生成图片
            // $data->picArr = serialize(Request::instance()->param('picArr/a'));                          //组图序列化
            $data->parentStr = parentStr(Request::instance()->param('parenTid'), 'information_type');   //parenStr方法
            $data->update_time = date('Y-m-d',time());
        });
    }


}